//dofile for evaluating and visualizing model's fit



**********Step 1: Age profiles of unemployment, NILF, and wages
import delimited "$dir/Model/simulated_data/simulated_data_base.csv", clear

//renaming
ren v1 theta
ren v2 e
ren v3 x
ren v4 a
ren v5 t
ren v6 p
ren v7 I
ren v8 H 
ren v9 tau
ren v10 s
ren v11 s_val
ren v12 prob_diff_I
ren v13 prob_diff_H
ren v14 l 
ren v15 m
ren v16 w
ren v17 tax
ren v18 c
ren v19 util
ren v20 switch
ren v21 gov_exp
ren v22 sim
ren v23 i_v

drop if e == 0
keep if t>=23 & t<=65

gen nilf = (l==0)
gen unemp = (l == 1 & m == 0)
gen emp = (m == 1)
replace w = . if m == 0 //recode 0 wages to missing

collapse (mean) emp nilf unemp w, by (t e)
reshape wide nilf unemp w emp, i(t) j(e)

ren nilf1 nilf_hs_s
ren nilf2 nilf_sc_s
ren nilf3 nilf_coll_s
ren unemp1 unemp_hs_s
ren unemp2 unemp_sc_s
ren unemp3 unemp_coll_s
ren w1 w_hs_s
ren w2 w_sc_s
ren w3 w_coll_s
ren emp1 emp_hs_s
ren emp2 emp_sc_s
ren emp3 emp_coll_s
save "$temp/age_prof_sim", replace


//import targeted moments for wages and unemployment
import delimited "$dir/Model/moments/age_profiles_emp.csv", clear
ren v1 t
ren v2 emp_hs
ren v5 emp_sc
ren v8 emp_coll
ren v3 unemp_hs
ren v6 unemp_sc
ren v9 unemp_coll
ren v4 nilf_hs
ren v7 nilf_sc
ren v10 nilf_coll
merge 1:1 t using "$temp/age_prof_sim", keep(match) nogen

twoway connected nilf_hs t, color(black) msize(vsmall) msymbol(circle) || connected nilf_hs_s t, color(black) lp(dash) msize(vsmall) msymbol(circle) || ///
connected nilf_sc t, color(black) msize(vsmall) msymbol(triangle) || connected nilf_sc_s t, color(black) lp(dash) msize(vsmall) msymbol(triangle) || ///
connected nilf_coll t, color(black) msize(vsmall) msymbol(square) || connected nilf_coll_s t, color(black) lp(dash) msize(vsmall) msymbol(square) ///
xtitle("Age") ytitle("NILF Rate") ///
legend(lab(1 "HS, Data") lab(2 "HS, Model") lab(3 "SC, Data") lab(4 "SC, Model") lab(5 "Coll, Data") lab(6 "Coll, Model"))
graph export "$output/model_fit_nilf.png", replace

twoway connected unemp_hs t, color(black) msize(vsmall) msymbol(circle) || connected unemp_hs_s t, color(black) lp(dash) msize(vsmall) msymbol(circle) || ///
connected unemp_sc t, color(black) msize(vsmall) msymbol(triangle) || connected unemp_sc_s t, color(black) lp(dash) msize(vsmall) msymbol(triangle) || ///
connected unemp_coll t, color(black) msize(vsmall) msymbol(square) || connected unemp_coll_s t, color(black) lp(dash) msize(vsmall) msymbol(square) ///
xtitle("Age") ytitle("Unemployment Rate") ///
legend(lab(1 "HS, Data") lab(2 "HS, Model") lab(3 "SC, Data") lab(4 "SC, Model") lab(5 "Coll, Data") lab(6 "Coll, Model"))
graph export "$output/model_fit_unemp.png", replace

twoway connected emp_hs t, color(black) msize(vsmall) msymbol(circle) || connected emp_hs_s t, color(black) lp(dash) msize(vsmall) msymbol(circle) || ///
connected emp_sc t, color(black) msize(vsmall) msymbol(triangle) || connected emp_sc_s t, color(black) lp(dash) msize(vsmall) msymbol(triangle) || ///
connected emp_coll t, color(black) msize(vsmall) msymbol(square) || connected emp_coll_s t, color(black) lp(dash) msize(vsmall) msymbol(square) ///
xtitle("Age") ytitle("Employment Rate") ///
legend(lab(1 "HS, Data") lab(2 "HS, Model") lab(3 "SC, Data") lab(4 "SC, Model") lab(5 "Coll, Data") lab(6 "Coll, Model"))
graph export "$output/model_fit_emp.png", replace

//now wages
import delimited "$dir/Model/moments/age_profiles_income.csv", clear
ren v1 t 
drop v3 v5 v7
ren v2 w_hs 
ren v4 w_sc 
ren v6 w_coll
merge 1:1 t using "$temp/age_prof_sim", keep(match) nogen

ds w_*
foreach var in `r(varlist)'{
	replace `var' = `var' * 4
}


twoway connected w_hs t, color(black) msize(vsmall) msymbol(circle) || connected w_hs_s t, color(black) lp(dash) msize(vsmall) msymbol(circle) || ///
connected w_sc t, color(black) msize(vsmall) msymbol(triangle) || connected w_sc_s t, color(black) lp(dash) msize(vsmall) msymbol(triangle) || ///
connected w_coll t, color(black) msize(vsmall) msymbol(square) || connected w_coll_s t, color(black) lp(dash) msize(vsmall) msymbol(square) ///
xtitle("Age") ytitle("Wage") ///
legend(lab(1 "HS, Data") lab(2 "HS, Model") lab(3 "SC, Data") lab(4 "SC, Model") lab(5 "Coll, Data") lab(6 "Coll, Model"))
graph export "$output/model_fit_w.png", replace
graph close
